﻿using System;
using System.Runtime.InteropServices;
using SharpDX.Multimedia;
using SharpDX.XAudio2;

namespace ScheduledXAudio2.Structures
{
    /// <summary>
    /// Composed of an XAudio2 AudioBuffer, VoiceSendDescriptor and a WaveFormat.
    /// The VoiceSendDescriptor's set accessor is not being set private on the 
    /// theory that it might be useful at some point in the future to move "Units"
    /// to different Submixers.
    /// </summary>
    [Serializable]
    [StructLayout(LayoutKind.Auto)]
    public class SimpleUnit
    {
        
        //AudioBuffer buffer;
        VoiceSendDescriptor vsd;
        //WaveFormat format;
       

        public SimpleUnit(AudioBuffer buffer, VoiceSendDescriptor vsd, WaveFormat format)
        {
            //"Backing field for automatically implemented property 'Buffer'
            //must be fully assigned before control is returned to caller."
            //Calling the default constructor prevents this error.
            

            Buffer = buffer;
            Vsd = vsd;
            Format = format;

            
            
            
        }
        public AudioBuffer Buffer
        {
            get;
            set;
        }

        public VoiceSendDescriptor Vsd
        {
            get { return vsd; }
            set { vsd = value; }
        }

        public WaveFormat Format
        {
            get;
            set;
        }  

        public void SetOutputVoice(SubmixVoice submixvoice)
        {
            vsd.OutputVoice = submixvoice;
        }

        public void Dispose()
        {
            
            //Buffer.Stream.Close();
            Buffer.Stream.Dispose();
        }
    }
}
